/**
 * 统计数字中1比特的数量
 */

#include <stdio.h>

int bitcount(unsigned x);

int main() {
    int x = 0x5050;
    printf("1 bits: %d\n", bitcount(x));

    return 0;
}

int bitcount(unsigned x) {
    int b;
    for (b = 0; x !=0; x >>= 1) {
        if (x & 1) b++;
    }

    return b;
}
